package com.sy;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @author songyi
 * @className TPMonitorFilter
 * @description TODO
 * @date 2020/8/17 0017 16:58
 */
@Activate(group = {CommonConstants.CONSUMER})
public class TPMonitorFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        long startTime = System.currentTimeMillis();
        try {
            return invoker.invoke(invocation);
        } finally {
            Constant.methodName.set(invocation.getMethodName());
            Constant.time.set(System.currentTimeMillis() - startTime);
        }
    }
}
